package com.apes.enquiry.supplier.santouliubi;

import com.alibaba.fastjson.JSONObject;
import com.apes.enquiry.supplier.santouliubi.model.ShopManagement;
import com.apes.enquiry.supplier.santouliubi.service.SantouEnquiryService;
import com.apes.enquiry.supplier.santouliubi.service.ShopManagementService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类描述：
 *
 * @ClassName santouService
 * @Description 描述
 * @Author wushilong
 * @Date 2023/1/5 9:07
 * @Version 1.0
 */
@Service
public class SantouService {

    @Autowired
    SantouliubiApi santouliubiApi;

    @Autowired
    private ShopManagementService shopManagementService;

    @Autowired
    private SantouEnquiryService santouEnquiryService;

    public JSONObject entrance(JSONObject json){
        switch (json.getInteger("code")){
            //门店注册成功
            case 1000105 :{
                return shopManagementService.informYes(json);
            }
            //门店注册失败
            case 1000110:{
                return shopManagementService.informNo(json);
            }
            //订单取消
            case 1001010:{
                return santouEnquiryService.cancelOrder(json);
            }
            //订单发货
            case 1001005:{
                return santouEnquiryService.newOrder(json);
            }
            //自动收货
            case 1001015:{
                return santouEnquiryService.confirmReceipt(json);
            }
            //测试
            case 1000000:{
                return santouEnquiryService.test(json);
            }
        }
        return null;
    }

    /**
     * 返回三头六臂接收成功格式
     * @param message
     * @return
     */
    public static JSONObject getJsonObject(String message) {
        JSONObject enroll = new JSONObject();
        enroll.put("code","1000");
        enroll.put("message", message);
        return enroll;
    }

    /**
     *
     * @param shopManagement 三头修理厂
     * @param productNumber 产品编号
     * @return
     */
    public JSONObject queryProduct(ShopManagement shopManagement, List productNumber, int page, int size){

        //拼装json对象向三头六臂发起询价
        JSONObject params = new JSONObject();
        params.put("merchantsId", shopManagement.getChannelNumber());//渠道商id
        params.put("garageNumber", shopManagement.getSantouId());//三头修理厂编号
        params.put("productNumber", productNumber.toArray());//产品品类
        params.put("page", page+1);//页码
        params.put("pageSize", size);//分页数
        //调用三头接口
       return santouliubiApi.queryProduct(params);
    }

    public JSONObject vinQueryProduct(ShopManagement shopManagement, String carExternalNumber, List categoryAll){
        //拼装json对象向三头六臂发起询价
        JSONObject params = new JSONObject();
        params.put("merchantsId", shopManagement.getChannelNumber());//渠道商id
        params.put("garageNumber", shopManagement.getSantouId());//三头修理厂编号
        params.put("carExternalNumber", carExternalNumber);//外部车型编号
        params.put("categoryIds", categoryAll.toArray());//产品品类
        params.put("hasStock", "20");//产品品类

        //调用三头接口
        return santouliubiApi.queryPrice(params);
    }
}
